package cn.tedu.blog.server.controller.system;
import cn.tedu.blog.server.pojo.dto.TagAddNewDTO;
import cn.tedu.blog.server.pojo.vo.TagDetailVO;
import cn.tedu.blog.server.pojo.vo.TagListItemVO;
import cn.tedu.blog.server.service.ITagService;
import cn.tedu.blog.server.utils.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Slf4j
@RestController
@Api(tags = "标签模块")
@RequestMapping("/tags")
public class TagController {
    @Autowired
    private ITagService tagService;

    @GetMapping("/select")
    public JsonResult select(){
        log.debug("====即将查询分类表，反馈表集合====");
        List<TagDetailVO> list=tagService.select();
        return JsonResult.ok(list);
    }

    @ApiOperationSupport(order = 100)
    @ApiOperation("添加标签")
    @PostMapping("/add-new")
    public JsonResult tagAddNew(@RequestBody TagAddNewDTO tagAddNewDTO){
        log.info("接受到的参数{}",tagAddNewDTO);
        tagService.addNew(tagAddNewDTO);
        return JsonResult.ok("添加成功");
    }

    @ApiOperationSupport(order = 300)
    @ApiOperation("编辑标签")
    @PostMapping("/update-by-id")
    public JsonResult update(@RequestBody TagAddNewDTO tagAddNewDTO){
        log.debug("接收到的请求参数：" + tagAddNewDTO);
        tagService.updateTag(tagAddNewDTO);
        return JsonResult.ok("修改成功");
    }

    @ApiOperation("删除标签")
    @ApiOperationSupport(order = 200)
    @PostMapping("/delete-by-ids")
    public JsonResult deleteByIds(@RequestBody List<Long> list){
        log.debug("deleteByIds方法:根据id删除标签,接收到的参数{}", list);
        String message = tagService.deleteByIds(list);
        return JsonResult.ok(message);
    }

    @ApiOperation("标签列表")
    @ApiOperationSupport(order = 400)
    @GetMapping("")
    public JsonResult list(){
        log.debug("list方法:查询标签列表");
        List<TagListItemVO> list = tagService.list();
        return JsonResult.ok(list);
    }
}
